moduleLearningMap.controller("AddLearningMapCourse", function (UploadFileService, $$CambioConfig, LearningMapCourseResource, $scope, $log, $state, $stateParams, GeneralResource, LoadingService, ConstantService, DialogService) {
    initPage($scope);
    $scope.$on("ngDialog.opened", function () {
        dialogOnLoad();
    });

    // ------------------------------------------------------------------------------------------------------

    $scope.cancel = function () {
        DialogService.close();
    };

    $scope.submit = function () {
        Alert.confirm(function () {
            LearningMapCourseResource.save({}, $scope.learningMapCourseDetail, function (result) {
                $scope.$parent.currentLearningMapCourseId = result.data.value;
                Alert.success();
                DialogService.close();
            });
        });
    };

    $scope.uploadCourseImage = function ($files) {
        if ($files && $files[0]) {
            UploadFileService.uploadFile($files[0], $$CambioConfig.UPLOAD_URL, 'IMG', $scope).then(function (o) {
                $scope.learningMapCourseDetail.picture = o.id;
            });
        }
    };
});